{
    "cells": [
        {
            "cell_type": "markdown",
            "id": "effeb5a7-8544-4ee4-8c11-bad0d8165394",
            "metadata": {},
            "source": [
                "# Slack Reader\n",
                "Demonstrates our Slack data connector"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "dc664882",
            "metadata": {},
            "outputs": [],
            "source": [
                "import logging\n",
                "import sys\n",
                "\n",
                "logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n",
                "logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "6ea1f66d-10ed-4417-bdcb-f8a894836ea5",
            "metadata": {},
            "outputs": [],
            "source": [
                "from llama_index import ListIndex, SlackReader\n",
                "from IPython.display import Markdown, display\n",
                "import os"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "da90589a-fb44-4ec6-9706-753dba4fa968",
            "metadata": {},
            "outputs": [],
            "source": [
                "slack_token = os.getenv(\"SLACK_BOT_TOKEN\")\n",
                "channel_ids = [\"<channel_id>\"]\n",
                "documents = SlackReader(slack_token=slack_token).load_data(channel_ids=channel_ids)"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "341295df-2029-4728-ab3d-2ee178a7e6f1",
            "metadata": {},
            "outputs": [],
            "source": [
                "index = ListIndex.from_documents(documents)"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "01c26b9d-49ec-4a6e-9c61-5c06bb86bbb2",
            "metadata": {},
            "outputs": [],
            "source": [
                "# set Logging to DEBUG for more detailed outputs\n",
                "query_engine = index.as_query_engine()\n",
                "response = query_engine.query(\"<query_text>\")"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "f160c678-2fb5-4d6d-b2bc-87abb61cfdec",
            "metadata": {},
            "outputs": [],
            "source": [
                "display(Markdown(f\"<b>{response}</b>\"))"
            ]
        }
    ],
    "metadata": {
        "kernelspec": {
            "display_name": "Python 3 (ipykernel)",
            "language": "python",
            "name": "python3"
        },
        "language_info": {
            "codemirror_mode": {
                "name": "ipython",
                "version": 3
            },
            "file_extension": ".py",
            "mimetype": "text/x-python",
            "name": "python",
            "nbconvert_exporter": "python",
            "pygments_lexer": "ipython3",
            "version": "3.11.1"
        }
    },
    "nbformat": 4,
    "nbformat_minor": 5
}
